package com.sq.partner.manager.service.impl;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sq.partner.manager.common.Constants;
import com.sq.partner.manager.dao.IGatewayTxLogDao;
import com.sq.partner.manager.mybatis.model.DeptDto;
import com.sq.partner.manager.mybatis.model.GatewayTxLog;
import com.sq.partner.manager.mybatis.model.GatewayUser;
import com.sq.partner.manager.service.IGatewayTxLogService;
import com.sq.partner.manager.util.Page;
import com.sq.partner.manager.util.StrUtil;
@Service
public class GatewayTxLogServiceImpl implements IGatewayTxLogService {

	@Resource
	private IGatewayTxLogDao gatewayTxLogDao ;
	
	@Override
	public Page getGatewayTxLog(String appId,String date,String appName,GatewayUser gatewayuser) throws SQLException {
		
		Page page=new Page();
		GatewayTxLog gatewayTxLog=new GatewayTxLog();
		gatewayTxLog.setAppId(appId);
		if(StrUtil.isEmpty(date)){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date sysdate = new Date();
			gatewayTxLog.setDate(sdf.format(sysdate));
		}else{
			gatewayTxLog.setDate(date);
		}
		if(null!=gatewayuser && StrUtil.isNotEmpty(gatewayuser.getDepartmentStr())){
			if(gatewayuser.getDepartmentStr().contains(Constants.HQ_BRANCH_CODE)){
				gatewayTxLog.setHqFlag("Y");
				gatewayTxLog.setDeptStr(gatewayuser.getDepartmentStr());
			}
		}
		gatewayTxLog.setDeptStr(gatewayuser.getDepartmentStr());
		page.setData(gatewayTxLogDao.getGatewayTxLog(gatewayTxLog));
		return page;
	}

	@Override
	public Page getErrorGatewayTxLog(String appId, String channelCode,String date,GatewayUser gatewayuser)throws SQLException  {
		Page page=new Page();
		GatewayTxLog gatewayTxLog=new GatewayTxLog();
		gatewayTxLog.setAppId(appId);
		gatewayTxLog.setDate(date);
		if(null!=gatewayuser && StrUtil.isNotEmpty(gatewayuser.getDepartmentStr())){
			if(gatewayuser.getDepartmentStr().contains(Constants.HQ_BRANCH_CODE)){
				gatewayTxLog.setHqFlag("Y");
				gatewayTxLog.setDeptStr(gatewayuser.getDepartmentStr());
			}
		}
		gatewayTxLog.setDeptStr(gatewayuser.getDepartmentStr());
		page.setData(gatewayTxLogDao.getErrorGatewayTxLogVo(gatewayTxLog));
		return page;
	}

	@Override
	public Page getChatDateLoad(String appId,String date,GatewayUser gatewayuser) throws SQLException {
		Page page=new Page();
		GatewayTxLog gtlo=new GatewayTxLog();
		gtlo.setAppId(appId);
		gtlo.setDate(date);
		if(null!=gatewayuser && StrUtil.isNotEmpty(gatewayuser.getDepartmentStr())){
			if(gatewayuser.getDepartmentStr().contains(Constants.HQ_BRANCH_CODE)){
				gtlo.setHqFlag("Y");
				gtlo.setDeptStr(gatewayuser.getDepartmentStr());
			}
		}
		gtlo.setDeptStr(gatewayuser.getDepartmentStr());
		page.setData(gatewayTxLogDao.getChatDateLoad(gtlo));
		return page;
	}

}
